package com.sgb.kjwl.viewmodel.pick;

import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.pick.PickExpertListEntity;
import com.sgb.kjwl.repository.PickRepertory;
import com.sgb.kjwl.view.ui.activity.pick.PickExpertDetailsActivity;
import com.sgb.kjwl.view.ui.activity.pick.PickExpertListActivity;
import com.sgb.zhaocai.entity.PickExpertDetailEntity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.base.model.entity.ListResponse;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.PickSelectEntity;
import com.swgk.core.view.areapopup.AddressEntity;
import com.swgk.core.view.selection.CommonPopEntity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class PickExpertListModel extends BaseViewModel {
    private PickRepertory repertory;
    private PickExpertListActivity activity;
    private Map map;
    private int pageSize = 10;

    public PickExpertListModel(PickExpertListActivity activity, PickRepertory repertory) {
        this.activity = activity;
        this.repertory = repertory;
    }

    //专家库-分页列表
    public void findPage(int page, String profession, String major, String categoryType, String area, String city, String fullName) {
        if (map == null)
            map = new HashMap();
        map.clear();

        map.put("profession", profession);
        map.put("major", major);
        map.put("categoryType", categoryType);
        map.put("province", area);
        map.put("city", city);
        map.put("fullName", fullName);

        map.put("page", page);
        map.put("limit", pageSize);

        DialogHelper.showProgressDialog2(activity.getActivity(), null, "获取信息中...", 0, false, null, false);
        APIManager.getInstance().getPickAPI().findPage(map).enqueue(new ICallBack<BaseEntity<ListResponse<List<PickExpertListEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<PickExpertListEntity>>> data) {
                if (data == null) {
                    activity.getExpertData(new ArrayList<>());
                }
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    activity.getExpertData(data.getData().getList());
                }
            }
        });
    }

    public void getProvinceData() {
        APIManager.getInstance().getPickAPI().getAddressEntityCityList().enqueue(new ICallBack<BaseEntity<List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>>>>() {
            @Override
            public void onSuccess(BaseEntity<List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>>> data) {
                if (data != null && data.getData() != null && data.getData().size() > 0) {
                    activity.setProvinceDatas(data.getData());
                }
            }
        });
    }

    //专家库列表专家职称筛选框
    public void getProfessionSelect() {
        APIManager.getInstance().getPickAPI().getProfessionSelect().enqueue(new ICallBack<BaseEntity<List<PickSelectEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<PickSelectEntity>> data) {
                if (data == null || data.getState() == null) {
                    return;
                }
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    activity.setTabLayoutData(data.getData());
                }
            }
        });
    }

    //专家库列表评标专业筛选框
    public void getMajorCategorySelect() {
        APIManager.getInstance().getPickAPI().getMajorCategorySelect().enqueue(new ICallBack<BaseEntity<List<CommonPopEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<CommonPopEntity>> data) {
                if (data == null || data.getState() == null) {
                    return;
                }
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    activity.setMajorCategorySelect(data.getData());
                }
            }
        });
    }

    //专家库列表所属类别筛选框
    public void getCategoryTypeSelect() {
        APIManager.getInstance().getPickAPI().getCategoryTypeSelect().enqueue(new ICallBack<BaseEntity<List<PickSelectEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<PickSelectEntity>> data) {
                if (data == null || data.getState() == null) {
                    return;
                }
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    activity.setCategoryTypeSelect(data.getData());
                }
            }
        });
    }

    //删除
    public void delete(String no,int position) {
        DialogHelper.showProgressDialog2(activity.getActivity(), null, "获取信息中...", 0, false, null, false);
        APIManager.getInstance().getPickAPI().delete(no).enqueue(new ICallBack<BaseEntity<BaseEntity>>() {
            @Override
            public void onSuccess(BaseEntity<BaseEntity> data) {
                if (data == null || data.getState() == null) {
                    return;
                }
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    activity.delete(position);
                }
            }
        });
    }

    //详情
    public void detail(String no) {
        APIManager.getInstance().getPickAPI().detail(no).enqueue(new ICallBack<BaseEntity<PickExpertDetailEntity>>() {
            @Override
            public void onSuccess(BaseEntity<PickExpertDetailEntity> data) {
                if (data == null || data.getState() == null) {
                    return;
                }
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    PickExpertDetailsActivity.start(activity, data.getData());
                }
            }
        });
    }
}
